﻿package smooth.core.object.googleMapCanvasComponent {
	import flash.display.Sprite;
	import flash.events.*;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.AntiAliasType;
	import flash.filters.*;
	
	public class GoogleMapCanvasMenu extends Sprite {
		[Embed(source="../../../../../resources/fonts/Arial.ttf", fontFamily="myFont")] 
		public var myFont:Class;
		
		private var initialWidth:int;
		private var initialHeight:int;
		private var initialPosX:int;
		private var initialPosY:int;
		private var initialColor:int;
		private var closeButton:TextField;
		private var normalMapButton:TextField;
		private var hybridMapButton:TextField;
		private var physicalMapButton:TextField;
		
		
		public function GoogleMapCanvasMenu(posX:int, posY:int, color:int) {
			// Init des attributs de l'objet
			this.initialPosX = posX;
			this.initialPosY = posY;
			this.initialColor = color;
			// Init des visuels du composant			
			initGraphics();
			// Init des events du composant
			initEvents();	
			// Init des process du composant
			initProcess();
		}
		
		private function initGraphics():void {
			var format:TextFormat= new TextFormat();
			format.font= "myFont";
			format.color= 0xFFFFFF;
			format.size = 15;
			
			this.closeButton = new TextField();
			this.closeButton.background = true;	
			this.closeButton.opaqueBackground = null;
			this.closeButton.backgroundColor = 0x000000;	
			this.closeButton.alpha = 0.5;
			this.closeButton.embedFonts = true;
			this.closeButton.selectable  = false;		 
			this.closeButton.text = "Close";
			this.closeButton.autoSize = TextFieldAutoSize.LEFT;
			this.closeButton.name = "Close";
			this.closeButton.width = 100;
			this.closeButton.height = 20;
			this.closeButton.x = this.initialPosX+10;
			this.closeButton.y = this.initialPosY+10;
			this.closeButton.setTextFormat(format);
			this.addChild(this.closeButton);	
			
			this.normalMapButton = new TextField();
			this.normalMapButton.background = true;	
			this.normalMapButton.opaqueBackground = null;
			this.normalMapButton.backgroundColor = 0x000000;	
			this.normalMapButton.alpha = 0.5;
			this.normalMapButton.embedFonts = true;
			this.normalMapButton.selectable  = false;		 
			this.normalMapButton.text = "Normal map";
			this.normalMapButton.autoSize = TextFieldAutoSize.LEFT;
			this.normalMapButton.name = "normalMap";
			this.normalMapButton.width = 100;
			this.normalMapButton.height = 20;
			this.normalMapButton.x = this.initialPosX+10;
			this.normalMapButton.y = this.initialPosY+40;
			this.normalMapButton.setTextFormat(format);
			this.addChild(this.normalMapButton);	
			
			this.hybridMapButton = new TextField();
			this.hybridMapButton.background = true;	
			this.hybridMapButton.opaqueBackground = null;
			this.hybridMapButton.backgroundColor = 0x000000;	
			this.hybridMapButton.alpha = 0.5;
			this.hybridMapButton.embedFonts = true;
			this.hybridMapButton.selectable  = false;		 
			this.hybridMapButton.text = "Hybrid map";
			this.hybridMapButton.autoSize = TextFieldAutoSize.LEFT;
			this.hybridMapButton.name = "hybridMap";
			this.hybridMapButton.width = 100;
			this.hybridMapButton.height = 20;
			this.hybridMapButton.x = this.initialPosX+10;
			this.hybridMapButton.y = this.initialPosY+70;
			this.hybridMapButton.setTextFormat(format);
			this.addChild(this.hybridMapButton);	
			
			this.physicalMapButton = new TextField();
			this.physicalMapButton.background = true;	
			this.physicalMapButton.opaqueBackground = null;
			this.physicalMapButton.backgroundColor = 0x000000;	
			this.physicalMapButton.alpha = 0.5;
			this.physicalMapButton.embedFonts = true;
			this.physicalMapButton.selectable  = false;		 
			this.physicalMapButton.text = "Physical map";
			this.physicalMapButton.autoSize = TextFieldAutoSize.LEFT;
			this.physicalMapButton.name = "physicalMap";
			this.physicalMapButton.width = 100;
			this.physicalMapButton.height = 20;
			this.physicalMapButton.x = this.initialPosX+10;
			this.physicalMapButton.y = this.initialPosY+100;
			this.physicalMapButton.setTextFormat(format);
			this.addChild(this.physicalMapButton);	
			
		}
		
		private function initProcess():void {
		}
		
		private function initEvents():void {
			this.closeButton.addEventListener(TouchEvent.MOUSE_DOWN, this.doClose);
			this.normalMapButton.addEventListener(TouchEvent.MOUSE_DOWN, this.doNormalMap);
			this.hybridMapButton.addEventListener(TouchEvent.MOUSE_DOWN, this.doHybridMap);
			this.physicalMapButton.addEventListener(TouchEvent.MOUSE_DOWN, this.doPhysicalMap);
		}
		
		private function doNormalMap(e:TouchEvent):void {
			if (this.parent.getNormalMapLayer() != null) {
				this.normalMapButton.backgroundColor = 0x000000;
				this.parent.doCloseNormalMapLayer();
			} else {	
				this.normalMapButton.backgroundColor = 0x009922;
				this.parent.doDisplayNormalMapLayer(0x009922);
			}
		}

		private function doHybridMap(e:TouchEvent):void {
			if (this.parent.getHybridMapLayer() != null) {
				this.hybridMapButton.backgroundColor = 0x000000;
				this.parent.doCloseHybridMapLayer();
			} else {	
				this.hybridMapButton.backgroundColor = 0x992200;
				this.parent.doDisplayHybridMapLayer(0x992200);
			}
		}
		
		private function doPhysicalMap(e:TouchEvent):void {
			if (this.parent.getPhysicalMapLayer() != null) {
				this.physicalMapButton.backgroundColor = 0x000000;
				this.parent.doClosePhysicalMapLayer();
			} else {	
				this.physicalMapButton.backgroundColor = 0x220099;
				this.parent.doDisplayPhysicalMapLayer(0x220099);
			}
		}

		private function doClose(e:TouchEvent):void {
			this.parent.removeComponent();
			e.stopPropagation();
		}
		
	}
	
}